package com;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HttpContext;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class StreamUploadDemo {

    public static void main(String[] args) throws IOException {
        RestTemplate restTemplate = new RestTemplate();
        FileInputStream inputStream =
                new FileInputStream(new File("/Users/lizhenxing-work/Desktop/150000187579768.mp4"));

        byte[] bytes = IOUtils.toByteArray(inputStream);
        System.out.println(bytes.length);


        HttpEntity entity = new ByteArrayEntity(bytes, ContentType.APPLICATION_OCTET_STREAM);
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        HttpPost post = new HttpPost("/monotonic/photo/audit/sync/brazil/150000187579768");
        post.setEntity(entity);
        CloseableHttpResponse response =
                httpClient.execute(HttpHost.create("https://oversea-photo-sync-br.corp.kuaishou.com"), post);
        System.err.println(response.getStatusLine());
        InputStream content = response.getEntity().getContent();
        String s = new String(IOUtils.toByteArray(response.getEntity().getContent()));
        System.out.println(s);

//        for (Object readLine : IOUtils.readLines(content)) {
//            System.err.println(readLine);
//        }
    }
}
